import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2024-11-02
 * Time:20:23
 */
//最小栈
    class MinStack {
    private Stack<Integer> stack;
    private Stack<Integer> minstack;
        public MinStack() {
            stack = new Stack<>();
            minstack = new Stack<>();
        }

        public void push(int val) {
            stack.push(val);
            if(minstack.isEmpty()){
                minstack.push(val);
            }else {
                if(val<=minstack.peek()){
                    minstack.push(val);
                }
            }
        }

        public void pop() {
            if(!stack.isEmpty()){
                int ret=stack.pop();
                if(minstack.peek()==ret){
                    minstack.pop();
                }
            }
        }

        public int top() {
            if(stack.isEmpty()){
                return -1;
            }
            return stack.peek();
        }

        public int getMin() {
            if(minstack.isEmpty()){
                return -1;
            }
            return minstack.peek();
        }
    }
